package com.jinlejia.erp.ui.common;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.erp.R;


/**
 * 没有权限（对话框）
 */

public class NoPermissionDialog extends AlertDialog implements View.OnClickListener {

    public NoPermissionDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.pop_no_permission);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        this.setCancelable(false);
//        this.setOnKeyListener(new OnKeyListener() {
//            @Override
//            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//                if (keyCode == KeyEvent.KEYCODE_SEARCH) {
//                    return true;
//                }else if (keyCode == KeyEvent.KEYCODE_BACK) {
//                    return true;
//                } else {
//                    return false; //默认返回 false
//                }
//            }
//        });
        //去授权
        TextView confirm = (TextView) window.findViewById(R.id.permission_confirm);

        confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.permission_confirm:
                //确定
                dismiss();
                if( null != confirmListener )
                confirmListener.confirm();
                break;
            default:
                break;
        }
    }

    public interface OnConfirmListener {
         void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }
}
